package com.shenzw.common.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

/**
 * 根据时间戳生成唯一id
 *
 * @author shenzw
 * @date 2024/03/01
 */
public class UniqueIdGenerator {

    public static String generateUniqueBatchNumber() {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        String timestamp = dateFormat.format(new Date());

        Random random = new Random();
        int randomNum = random.nextInt(1000);  // 生成 0 到 999 之间的随机数

        return timestamp + String.format("%03d", randomNum);
    }

    public static void main(String[] args) {
        for (int i = 0; i < 100; i++) {
            String uniqueBatchNumber = generateUniqueBatchNumber();
            System.out.println("Generated Unique Batch Number: " + uniqueBatchNumber);
        }
    }
}

